import requests


class TestIHRMLogin:

    #登录成功
    def test_login_success(self):
        #设置url,header,body，发送http post请求，获取响应结果
        url = "http://ihrm-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        json_data = {"mobile": "13800000002","password": "123456"}
        resp = requests.post(url=url,headers=header,json=json_data)
        print("resp=",resp.json())
        #断言
        assert resp.status_code ==200
        assert resp.json().get("success") == True
        assert resp.json().get("code") == 10000
        assert resp.json().get("message") == '操作成功！'


    #账号错误
    def test_username_error(self):
        # 设置url,header,body，发送http post请求，获取响应结果
        url = "http://ihrm-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        json_data = {"mobile": "138000000021", "password": "123456"}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("resp=", resp.json())
        # 断言
        assert resp.status_code == 200
        assert resp.json().get("success") == False
        assert resp.json().get("code") == 20001
        assert resp.json().get("message") == '用户名或密码错误'

    #密码错误
    def test_password_error(self):
        # 设置url,header,body，发送http post请求，获取响应结果
        url = "http://ihrm-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        json_data = {"mobile": "13800000002", "password": "1234561"}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("resp=", resp.json())
        # 断言
        assert resp.status_code == 200
        assert resp.json().get("success") == False
        assert resp.json().get("code") == 20001
        assert resp.json().get("message") == '用户名或密码错误'

    pass
